<?
require_once "inc.init.php";

// THE OBJ:
$obj = new clientes(); // <---- Change this !!!
$obj-> setDbLink($dbLink);

// GETTING:
$obj->get( $_GET[$obj->_dbIndex] );
$isNew = $obj->getID()?FALSE:TRUE;

// MESSENGER
$messenger = new Messenger();

// SAVING:
if ($_POST['action'] == 'save') 
{
	if ($user->isEnabledTo("write", $module->id))
	{
		$obj->set($_POST, true);
                $obj->userID_modified=$user->getID();

		if($obj->save())
		{
			header("location: ./details.php?".$obj->_dbIndex."=".$obj->getID());
			exit();
		}
		else $messenger->addMessage("Se ha producido un error interno, por favor: reintente.");
	}
	else $messenger->addMessage($lang->translate("user_action_denied"));
}

include DIR_ADMIN.'/common/inc.header.php';
?>
</head>
<body>
    <div class="Path">
        <a href="."><?= $module->name ?></a> &gt;
        <h1>
    	<?
    	if ($obj->getID())
		{
		    ?><a href="details.php?<?= $obj->_dbIndex ?>=<?= $obj->getID() ?>"><?= $obj->nombre_apellido ?></a><? 
		}
		else
		{
		    ?>Agregando <?= strtolower($module->unit) ?><?
    	}
    	?>
	    </h1>
    </div>
    <?
    // AND THE ERRORS ^^
    echo $messenger? $messenger->getMessages() : '';
    ?>
    <div class="tableHeader"><strong>Editando</strong></div>
    <form action="" method="post" enctype="multipart/form-data">
        <table cellspacing="0" class="AbmTable">
            <tr>
                <td width="120" height="13"> Nombre y Apellido:</td>
                <td><input type="text" name="nombre_apellido" value="<?= $obj->nombre_apellido ?>"></td>
            </tr>
            <tr>
                <td valign="top">Email:</td>
                <td><input type="text" name="email" value="<?= $obj->email ?>"></td>
            </tr>
            <tr>
                <td valign="top">Teléfono:</td>
                <td><input type="text" name="telefono" value="<?= $obj->telefono ?>"></td>
            </tr>
            <tr>
                <td valign="top">Celular:</td>
                <td><input type="text" name="celular" value="<?= $obj->celular ?>"></td>
            </tr>

            <tr>
                <td valign="top">Dirección:</td>
                <td><input type="text" name="direccion" value="<?= $obj->direccion ?>"></td>
            </tr>
            <tr>
                <td colspan="2">
                    <br>
                    <strong>Datos Administrativos</strong>
                </td>
            </tr>
            <tr>
                <td>Activo:</td>
                <td><input type="checkbox" <?= $obj->active == 'Y' ? "checked" : '' ?> name="active" value="Y"></td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <a class="button" href="details.php?<?= $obj->_dbIndex ?>=<?= $obj->getID() ?>"><span>Cancelar</span></a>
                    <span class="button">
                        <input type="submit" style="font-weight:bold;" value="Guardar" name="Guardar">
                    </span>
                </td>
            </tr>
        </table>
        <input type="hidden" name="action" value="save">
    </form>
    
    <div class="tableHeader"><strong>Info de sistema </strong></div>
    <table cellspacing="0" class="AbmTable">
        <tr>
            <td width="15%"><?= $module->unit ?> id: </td>
            <td colspan="3"><?= $obj->getID() ?></td>
        </tr>
        <tr>
            <td>Fecha de creaci&oacute;n :</td>
            <td><?= $obj->date_created ?></td>
            <td width="15%">Fecha &uacute;ltimo cambio:</td>
            <td><?= $obj->date_modified ?></td>
        </tr>
        <tr>
            <td>Usuario que cre&oacute;:</td>
            <td><?= $obj->userCreated ?></td>
            <td>Usuario que modific&oacute;:</td>
            <td><?= $obj->userModified ?></td>
        </tr>
    </table>
</body>
</html>
